package com.five.wisdomEat.controller;

import com.five.wisdomEat.entity.Dishes;
import com.five.wisdomEat.entity.ResponseMessage;
import com.five.wisdomEat.service.DishesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@CrossOrigin
@RestController
@RequestMapping("/dishes")
public class DishesController {
    @Autowired
    private DishesService service;

    @GetMapping("/getDishesList")
    public ResponseMessage getDishesAll(String bNumber){
        return service.getDishesAll(bNumber);
    }

    @PostMapping("/insertDishes")
    public ResponseMessage insertDishes(String bNumber,String dNumber, String dName, Integer dTypeId, Double dPrice, Integer dCount, String dWeight ){
        Dishes dishes = new Dishes();
        dishes.setBNumber(bNumber);
        dishes.setDNumber(dNumber);
        dishes.setDName(dName);
        dishes.setDTypeId(dTypeId);
        dishes.setDPrice(dPrice);
        dishes.setDCount(dCount);
        dishes.setDWeight(dWeight);
        return service.insertDishes(dishes);
    }

    @PostMapping("/updateDishes")
    public ResponseMessage updateDishes(String dNumber, String dName, Integer dTypeId, Double dPrice, Integer dCount, String dWeight ){
        Dishes dishes = new Dishes();
        dishes.setDNumber(dNumber);
        dishes.setDName(dName);
        dishes.setDTypeId(dTypeId);
        dishes.setDPrice(dPrice);
        dishes.setDCount(dCount);
        dishes.setDWeight(dWeight);
        return service.updateDishes(dishes);
    }

    @PostMapping("/deleteDishes")
    public ResponseMessage insertDishes(String dNumber){
        return service.deleteDishes(dNumber);
    }

    @PostMapping("/onSaleDishes")
    public ResponseMessage onSaleDishes(String dNumber){
        return service.onSaleDishes(dNumber);
    }

    @PostMapping("/offShelfDishes")
    public ResponseMessage offShelfDishes(String dNumber){
        return service.offShelfDishes(dNumber);
    }

    @GetMapping("/selectDishesListByExample")
    public ResponseMessage selectDishesListByExample(String bNumber,String dNumber, String dName, Integer dTypeId,Integer dStateId ){
        Dishes dishes = new Dishes();
        dishes.setBNumber(bNumber);
        dishes.setDNumber(dNumber);
        dishes.setDName(dName);
        dishes.setDTypeId(dTypeId);
        dishes.setDStateId(dStateId);
        return service.insertDishes(dishes);
    }

}
